Skip to content

feat: add viewModel and replaceViewModel for nested ViewModel access#96

Merged
mfazekas merged 1 commit into
mainfrom
feat/viewmodel-instance-property
Jan 7, 2026
Merged

feat: add viewModel and replaceViewModel for nested ViewModel access#96
mfazekas merged 1 commit into
mainfrom
feat/viewmodel-instance-property

Conversation

@mfazekas
Copy link
Copy Markdown
Collaborator

@mfazekas mfazekas commented Dec 23, 2025

Summary

Adds two methods to ViewModelInstance for accessing and replacing nested ViewModel instances:

  • viewModel(path) - get a nested ViewModelInstance by path
  • replaceViewModel(path, instance) - replace a nested instance with another

API naming follows the Web SDK conventions (@rive-app/canvas).

Example

// Get nested ViewModel instance
const nestedVM = instance.viewModel('vm2');

// Replace vm1 with vm2's instance
const success = instance.replaceViewModel('vm1', nestedVM);

// After replacement, vm1 and vm2 share the same instance
// Call playIfNeeded() to refresh the display
riveRef.current?.playIfNeeded();

Test file

Includes viewmodelproperty.riv - a custom test file with nested ViewModels (vm1, vm2) to demonstrate the feature.

https://rive.app/community/files/25668-47939-demo-file-for-runtime-replaceviewmodel

@mfazekas mfazekas force-pushed the feat/viewmodel-instance-property branch from 65196b5 to 474ce91 Compare December 23, 2025 08:39
@mfazekas mfazekas force-pushed the feat/viewmodel-instance-property branch from 474ce91 to b68b299 Compare January 7, 2026 07:25
@mfazekas mfazekas changed the title feat: add viewModelInstanceProperty for nested ViewModel access feat: add viewModel and replaceViewModel for nested ViewModel access Jan 7, 2026
@mfazekas mfazekas force-pushed the feat/viewmodel-instance-property branch from b68b299 to b3fca2d Compare January 7, 2026 08:09
@mfazekas mfazekas marked this pull request as ready for review January 7, 2026 08:23
@mfazekas mfazekas requested a review from HayesGordon January 7, 2026 08:24
@mfazekas mfazekas enabled auto-merge (squash) January 7, 2026 08:25
Copy link
Copy Markdown
Contributor

@HayesGordon HayesGordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mfazekas mfazekas merged commit 3f61c98 into main Jan 7, 2026
6 of 7 checks passed
@mfazekas mfazekas deleted the feat/viewmodel-instance-property branch January 7, 2026 09:43
mfazekas added a commit that referenced this pull request Jan 8, 2026
## Summary
Add missing `import NitroModules` to `HybridViewModelInstance.swift`.
This import is required for `RuntimeError` which is used in the
`replaceViewModel` method added in #96.

## Note on CI
The iOS build in #96 passed because CI may have cached the build or the
error only surfaces in clean builds. This fix resolves the build error.
mfazekas pushed a commit that referenced this pull request Jan 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.4](v0.1.3...v0.1.4)
(2026-01-09)


### Features

* add data binding artboards support
([#95](#95))
([515070e](515070e))
* add release-please for automated releases
([#109](#109))
([6403bd4](6403bd4))
* add viewModel and replaceViewModel for nested ViewModel access
([#96](#96))
([3f61c98](3f61c98))


### Bug Fixes

* read initial value in useRiveProperty hooks
([#97](#97))
([26223f2](26223f2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
mfazekas added a commit that referenced this pull request Jan 12, 2026
## Summary
- Add in-app test runner using react-native-harness for assertions
- Add Tests page to example app for running tests on device
- Initial tests for `viewModel()` and `replaceViewModel()` from #96

## Test plan
- Run example app and navigate to "Tests" page
- Tap "Run All Tests" to verify both tests pass

<img height="800" alt="image"
src="https://github.com/user-attachments/assets/630354c3-1295-49d7-b26b-c9e9d8af469d"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants